     <?php
autenticacao("vendas");
include_once 'Controle/vendas.php';
echo "
    <a href='".url("pag", "venda_set")."' name='Novo'><button class='botaonovo'><label>Nova&nbspVenda</label></button></a>
    <a href='".url("pag", "venda_consulta")."' name='Consultar'><button class='botaoconsultar'><label>Consultar&nbspVenda</label></button></a>
    "?>

          <div id='divconsultarapida' style="margin-top: 20px;">
             <p style='width: 160px'>Consulta Rápida</p>
             <form action='<?php echo url("pag", "vendas")?>' method='post' class='formulario'>
                  <label class='campos'>ID Venda: </label>
                  <input type='text' value='' name='idvenda' id='idvenda' style='width: 80px'/>
                  
                  <label class='campos'>Cliente: </label>
                  <input type='text' value='' name='cliente' id='cliente' style='width: 615px'/>
                  
                  <input type='submit' value='Ok' name='btn_ok' class='botaook'/>
                       
             </form>
             
        </div> 


     <?php

$btn_ok = $_POST["btn_ok"];
$b_id = $_POST["idvenda"];
$b_cliente = $_POST["cliente"];

if($btn_ok == "Ok"){
     if ($b_id != '' && valida::numero($b_id)) {
          
          $sql = "select id from Venda where filial = '".$_SESSION["angel_filial"]."' and id like '%$b_id%' order by id";    
                    
     } elseif ($b_cliente != '' && valida::nome($b_cliente)) {  
          
            $sql = "SELECT v.id FROM Venda v, Cliente c WHERE v.filial = '".$_SESSION["angel_filial"]."' AND c.nome like '%$b_cliente%' AND v.idCliente = c.id order by c.nome";
          
     } else { 
          
          $sql = "select id from Venda where filial = '".$_SESSION["angel_filial"]."' order by data desc";
          
     }
     
} else {

     $sql = "select id from Venda where filial = '".$_SESSION["angel_filial"]."' order by data desc LIMIT 40";
     
}
          
       echo "
      <table class='tabela'>
            <tr>
                <th><label>ID</label></th>
                <th><label>Data</label></th>
                <th><label>Cliente</label></th>
                <th><label>Valor</label></th>
                <th><label>Forma de Pagamento</label></th>
                <th>
                    <input type='checkbox' id='ch_principal' onClick='marcar_todoas(this.id)' />
                </th>
        </tr>";
$cor[0] = "#FFF";
$cor[1] = "#DDD";
$cnt = 0;
//$sql = "select id from Venda where filial = '".$_SESSION["angel_filial"]."' order by data desc LIMIT 40";
$conexao = db::conecta();
$result  = db::query($sql, $conexao);
while ($idv = db::fetch_array($result)){
    $venda = new Venda();
    $venda->carregar($idv[0]);
    echo "
    <tr style='background: ".$cor[$cnt]."'>
        <td><label>".$venda->get_id()."</label></td>
        <td><label>".$venda->get_data()." ".$venda->get_hora()."</label></td>
        <td class='bot_tabela'><a href='".url("pag", "venda_print")."&idvenda=".$venda->get_id()."' name='Consultar por ".$venda->get_id()."'<label>".$venda->get_cliente()."</label></td>
        <td><label>".$venda->get_total()."</label></td>
        <td><label>".formapagamento($venda->get_formapagamento())."</label></td>
        <td>";
        ?>
<input type='checkbox' value='<?php echo $venda->get_total(); ?>' id='ch_<?php echo $venda->get_id(); ?>' class='ch' onClick="soma_val_marc(this.value, this.id)" />
            
        <?php
        echo "
        </td>
    </tr>";
    if($cnt == 1){ $cnt = 0; }else{ $cnt++; }
}

echo "</table>";
     
echo "
    <div class='marcado'>
         <label class='campos'>Valor Marcado: </label> <input type='text' value='0' id='val_marc' readonly='readonly' class='readonly' />
    </div>
    <a href='".url("pag", "venda_set")."' name='Novo'><button class='botaonovo'><label>Nova&nbspVenda</label></button></a>
    <a href='".url("pag", "venda_consulta")."' name='Consultar'><button class='botaoconsultar'><label>Consultar&nbspVenda</label></button></a>
    
        
    <br /><br />
    <a href='".url("pag", "")."' name='Voltar'><button class='botaovoltar'><label>Voltar</label></button></a>
    ";
?>
